﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import Events.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import __AS3__.vec.*;
    import Classes.effects.*;
    import Display.*;
    import Mechanics.GameEventMechanics.*;

    public class GMMechanicStore extends GMEdit {

        protected static var m_seenWarning:Boolean = false;

        private var m_storage:IMechanicUser;
        private var m_storables:Vector.<GameObject>;

        public function GMMechanicStore(_arg1:IMechanicUser){
            m_uiMode = UIEvent.STORE;
            this.m_storage = _arg1;
            this.m_storables = this.getStorables(this.m_storage);
            this.addPulsateEffects();
        }
        protected function getStorables(_arg1:IMechanicUser):Vector.<GameObject>{
            var _local6:MapResource;
            var _local2:Vector.<GameObject> = new Vector.<GameObject>();
            if ((((_arg1 == null)) || (!(_arg1.getMechanicConfig("slots", Global.getClassName(this)))))){
                return (_local2);
            };
            var _local3:MechanicManager = MechanicManager.getInstance();
            var _local4:IStorage = (_local3.getMechanicInstance(_arg1, "slots", Global.getClassName(this)) as IStorage);
            var _local5:Array = Global.world.getObjects();
            if (_local4 != null){
                for each (_local6 in _local5) {
                    if (_local4.canStore(_local6)){
                        _local2.push(_local6);
                    };
                };
            };
            return (_local2);
        }
        protected function addPulsateEffects():void{
            var _local1:MapResource;
            if (this.m_storables == null){
                return;
            };
            for each (_local1 in this.m_storables) {
                _local1.addAnimatedEffect(EffectType.PULSATE_GLOW);
            };
        }
        protected function removePulsateEffects():void{
            var _local1:MapResource;
            if (!this.m_storables){
                return;
            };
            for each (_local1 in this.m_storables) {
                _local1.removeAnimatedEffects();
            };
        }
        override public function get supportsEditing():Boolean{
            return (false);
        }
        override public function disableMode():void{
            this.removePulsateEffects();
            super.disableMode();
        }
        override protected function isObjectSelectable(_arg1:GameObject):Boolean{
            if (GMEdit.isLocked){
                return (false);
            };
            var _local2:IStorage = (MechanicManager.getInstance().getMechanicInstance(this.m_storage, "slots", Global.getClassName(this)) as IStorage);
            return ((((((_arg1 is MapResource)) && (_local2))) && (_local2.canStore((_arg1 as MapResource)))));
        }
        override protected function canBeClicked(_arg1:MouseEvent):Boolean{
            return (((!((m_highlightedObject == null))) && (!(Global.isVisiting()))));
        }
        override protected function getCursor():Object{
            return (EmbeddedArt.hud_act_mall);
        }
        override public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local2:MapResource;
            var _local3:String;
            var _local4:GenericDialog;
            if (UI.resolveIfAssetsHaveNotLoaded(DelayedAssetLoader.GENERIC_DIALOG_ASSETS)){
                finishMouseUpEvent();
                return (false);
            };
            if (m_selectedObject == null){
                finishMouseUpEvent();
                return (false);
            };
            super.onMouseUp(_arg1);
            if (((!(m_seenWarning)) && ((m_selectedObject as MapResource).warnForStorage()))){
                m_seenWarning = true;
                _local2 = (m_selectedObject as MapResource);
                _local3 = ZLoc.t("Dialogs", "MechanicStoreWarning", {
                    storeTarget:_local2.getItemFriendlyName(),
                    storage:(this.m_storage as MechanicMapResource).getItemFriendlyName()
                });
                _local4 = new GenericDialog(_local3, "storageWarning", GenericDialogView.TYPE_YESNO, this.warningHandler);
                UI.displayPopup(_local4);
                finishMouseUpEvent();
                return (false);
            };
            this.handleMallStore();
            return (true);
        }
        private function handleMallStore():void{
            var _local1:Array = new Array();
            _local1["mode"] = GatedStorageMechanic.MODE_STORE;
            _local1["object"] = m_selectedObject;
            var _local2:Boolean = MechanicManager.getInstance().handleAction(this.m_storage, Global.getClassName(this), _local1);
            Global.ui.dispatchEvent(new GenericObjectEvent(GenericObjectEvent.OBJECT_STORED, null));
            deselectObject();
            dehighlightObject();
            if (_local2){
                Global.world.addGameMode(new GMPlay());
            };
        }
        private function warningHandler(_arg1:GenericPopupEvent):void{
            if (_arg1.button == GenericPopup.YES){
                this.handleMallStore();
            } else {
                m_seenWarning = false;
            };
        }

    }
}//package GameMode 
